Fix #129020.
authorFederico Mena Quintero <federico@ximian.com>
Sat, 14 Feb 2004 01:23:58 +0000 (01:23 +0000)
committerFederico Mena Quintero <federico@src.gnome.org>
Sat, 14 Feb 2004 01:23:58 +0000 (01:23 +0000)
2004-02-13  Federico Mena Quintero  <federico@ximian.com>

Fix #129020.

* gtk/gtkfilechooserdialog.c
(set_default_size): New function, sets a reasonable default size
for the window.
(gtk_file_chooser_dialog_realize): New function, call
set_default_size().
(gtk_file_chooser_dialog_style_set): Likewise.
(gtk_file_chooser_dialog_screen_changed): Likewise.

* tests/testfilechooser.c (main): Don't set a default size for the
dialog.

ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
gtk/gtkfilechooserdialog.c

index a30ec5d1deea6db3c68badbd38e5404e49bc032f..0c3655c9ffe5058ccc310b42f03c82c2514d06d7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2004-02-13  Federico Mena Quintero  <federico@ximian.com>
+
+       Fix #129020.
+
+       * gtk/gtkfilechooserdialog.c
+       (set_default_size): New function, sets a reasonable default size
+       for the window.
+       (gtk_file_chooser_dialog_realize): New function, call
+       set_default_size().
+       (gtk_file_chooser_dialog_style_set): Likewise.
+       (gtk_file_chooser_dialog_screen_changed): Likewise.
+
+       * tests/testfilechooser.c (main): Don't set a default size for the
+       dialog.
+
 Sat Feb 14 00:05:18 2004  Matthias Clasen  <maclas@gmx.de>
 
        * gtk/gtktreemodelfilter.c (bsearch_elt_with_offset): 
@@ -13,7 +28,6 @@ Fri Feb 13 23:54:48 2004  Matthias Clasen  <maclas@gmx.de>
        * configure.in: Remove checks for sgml2html. It was once
        used for building the linuxdoc version of the tutorial.
        Nowadays, we use db2html.  (#134164, Julio M. Merino Vidal)
-       
 
 Fri Feb 13 08:17:43 2004  Owen Taylor  <otaylor@redhat.com>
 
index a30ec5d1deea6db3c68badbd38e5404e49bc032f..0c3655c9ffe5058ccc310b42f03c82c2514d06d7 100644 (file)
@@ -1,3 +1,18 @@
+2004-02-13  Federico Mena Quintero  <federico@ximian.com>
+
+       Fix #129020.
+
+       * gtk/gtkfilechooserdialog.c
+       (set_default_size): New function, sets a reasonable default size
+       for the window.
+       (gtk_file_chooser_dialog_realize): New function, call
+       set_default_size().
+       (gtk_file_chooser_dialog_style_set): Likewise.
+       (gtk_file_chooser_dialog_screen_changed): Likewise.
+
+       * tests/testfilechooser.c (main): Don't set a default size for the
+       dialog.
+
 Sat Feb 14 00:05:18 2004  Matthias Clasen  <maclas@gmx.de>
 
        * gtk/gtktreemodelfilter.c (bsearch_elt_with_offset): 
@@ -13,7 +28,6 @@ Fri Feb 13 23:54:48 2004  Matthias Clasen  <maclas@gmx.de>
        * configure.in: Remove checks for sgml2html. It was once
        used for building the linuxdoc version of the tutorial.
        Nowadays, we use db2html.  (#134164, Julio M. Merino Vidal)
-       
 
 Fri Feb 13 08:17:43 2004  Owen Taylor  <otaylor@redhat.com>
 
index a30ec5d1deea6db3c68badbd38e5404e49bc032f..0c3655c9ffe5058ccc310b42f03c82c2514d06d7 100644 (file)
@@ -1,3 +1,18 @@
+2004-02-13  Federico Mena Quintero  <federico@ximian.com>
+
+       Fix #129020.
+
+       * gtk/gtkfilechooserdialog.c
+       (set_default_size): New function, sets a reasonable default size
+       for the window.
+       (gtk_file_chooser_dialog_realize): New function, call
+       set_default_size().
+       (gtk_file_chooser_dialog_style_set): Likewise.
+       (gtk_file_chooser_dialog_screen_changed): Likewise.
+
+       * tests/testfilechooser.c (main): Don't set a default size for the
+       dialog.
+
 Sat Feb 14 00:05:18 2004  Matthias Clasen  <maclas@gmx.de>
 
        * gtk/gtktreemodelfilter.c (bsearch_elt_with_offset): 
@@ -13,7 +28,6 @@ Fri Feb 13 23:54:48 2004  Matthias Clasen  <maclas@gmx.de>
        * configure.in: Remove checks for sgml2html. It was once
        used for building the linuxdoc version of the tutorial.
        Nowadays, we use db2html.  (#134164, Julio M. Merino Vidal)
-       
 
 Fri Feb 13 08:17:43 2004  Owen Taylor  <otaylor@redhat.com>
 
index a30ec5d1deea6db3c68badbd38e5404e49bc032f..0c3655c9ffe5058ccc310b42f03c82c2514d06d7 100644 (file)
@@ -1,3 +1,18 @@
+2004-02-13  Federico Mena Quintero  <federico@ximian.com>
+
+       Fix #129020.
+
+       * gtk/gtkfilechooserdialog.c
+       (set_default_size): New function, sets a reasonable default size
+       for the window.
+       (gtk_file_chooser_dialog_realize): New function, call
+       set_default_size().
+       (gtk_file_chooser_dialog_style_set): Likewise.
+       (gtk_file_chooser_dialog_screen_changed): Likewise.
+
+       * tests/testfilechooser.c (main): Don't set a default size for the
+       dialog.
+
 Sat Feb 14 00:05:18 2004  Matthias Clasen  <maclas@gmx.de>
 
        * gtk/gtktreemodelfilter.c (bsearch_elt_with_offset): 
@@ -13,7 +28,6 @@ Fri Feb 13 23:54:48 2004  Matthias Clasen  <maclas@gmx.de>
        * configure.in: Remove checks for sgml2html. It was once
        used for building the linuxdoc version of the tutorial.
        Nowadays, we use db2html.  (#134164, Julio M. Merino Vidal)
-       
 
 Fri Feb 13 08:17:43 2004  Owen Taylor  <otaylor@redhat.com>
 
index a30ec5d1deea6db3c68badbd38e5404e49bc032f..0c3655c9ffe5058ccc310b42f03c82c2514d06d7 100644 (file)
@@ -1,3 +1,18 @@
+2004-02-13  Federico Mena Quintero  <federico@ximian.com>
+
+       Fix #129020.
+
+       * gtk/gtkfilechooserdialog.c
+       (set_default_size): New function, sets a reasonable default size
+       for the window.
+       (gtk_file_chooser_dialog_realize): New function, call
+       set_default_size().
+       (gtk_file_chooser_dialog_style_set): Likewise.
+       (gtk_file_chooser_dialog_screen_changed): Likewise.
+
+       * tests/testfilechooser.c (main): Don't set a default size for the
+       dialog.
+
 Sat Feb 14 00:05:18 2004  Matthias Clasen  <maclas@gmx.de>
 
        * gtk/gtktreemodelfilter.c (bsearch_elt_with_offset): 
@@ -13,7 +28,6 @@ Fri Feb 13 23:54:48 2004  Matthias Clasen  <maclas@gmx.de>
        * configure.in: Remove checks for sgml2html. It was once
        used for building the linuxdoc version of the tutorial.
        Nowadays, we use db2html.  (#134164, Julio M. Merino Vidal)
-       
 
 Fri Feb 13 08:17:43 2004  Owen Taylor  <otaylor@redhat.com>
 
index 2067f076e26df7650d023980ed3026d226370241..157768571e6b851e31a6d628d6a04d5c49a9fbca 100644 (file)
 
 #include <stdarg.h>
 
+#define NUM_LINES 40
+#define NUM_CHARS 50
+
 struct _GtkFileChooserDialogPrivate
 {
   GtkWidget *widget;
-  
+
   GtkFileSystem *file_system;
 };
 
@@ -50,6 +53,12 @@ static void     gtk_file_chooser_dialog_get_property (GObject               *obj
                                                      GValue                *value,
                                                      GParamSpec            *pspec);
 
+static void gtk_file_chooser_dialog_realize        (GtkWidget *widget);
+static void gtk_file_chooser_dialog_style_set      (GtkWidget *widget,
+                                                   GtkStyle  *previous_style);
+static void gtk_file_chooser_dialog_screen_changed (GtkWidget *widget,
+                                                   GdkScreen *previous_screen);
+
 static GObjectClass *parent_class;
 
 GType
@@ -71,7 +80,7 @@ gtk_file_chooser_dialog_get_type (void)
        0,              /* n_preallocs */
        (GInstanceInitFunc) gtk_file_chooser_dialog_init,
       };
-      
+
       static const GInterfaceInfo file_chooser_info =
       {
        (GInterfaceInitFunc) _gtk_file_chooser_delegate_iface_init, /* interface_init */
@@ -93,6 +102,7 @@ static void
 gtk_file_chooser_dialog_class_init (GtkFileChooserDialogClass *class)
 {
   GObjectClass *gobject_class = G_OBJECT_CLASS (class);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
 
   parent_class = g_type_class_peek_parent (class);
 
@@ -100,6 +110,10 @@ gtk_file_chooser_dialog_class_init (GtkFileChooserDialogClass *class)
   gobject_class->set_property = gtk_file_chooser_dialog_set_property;
   gobject_class->get_property = gtk_file_chooser_dialog_get_property;
 
+  widget_class->realize = gtk_file_chooser_dialog_realize;
+  widget_class->style_set = gtk_file_chooser_dialog_style_set;
+  widget_class->screen_changed = gtk_file_chooser_dialog_screen_changed;
+
   _gtk_file_chooser_install_properties (gobject_class);
 
   g_type_class_add_private (class, sizeof (GtkFileChooserDialogPrivate));
@@ -131,7 +145,7 @@ gtk_file_chooser_dialog_constructor (GType                  type,
 {
   GtkFileChooserDialogPrivate *priv;
   GObject *object;
-                                                                 
+
   object = parent_class->constructor (type,
                                      n_construct_properties,
                                      construct_params);
@@ -165,7 +179,7 @@ gtk_file_chooser_dialog_set_property (GObject         *object,
                                      guint            prop_id,
                                      const GValue    *value,
                                      GParamSpec      *pspec)
-     
+
 {
   GtkFileChooserDialogPrivate *priv = GTK_FILE_CHOOSER_DIALOG_GET_PRIVATE (object);
 
@@ -197,10 +211,88 @@ gtk_file_chooser_dialog_get_property (GObject         *object,
                                      GParamSpec      *pspec)
 {
   GtkFileChooserDialogPrivate *priv = GTK_FILE_CHOOSER_DIALOG_GET_PRIVATE (object);
-  
+
   g_object_get_property (G_OBJECT (priv->widget), pspec->name, value);
 }
 
+static void
+set_default_size (GtkFileChooserDialog *dialog)
+{
+  GtkWidget *widget;
+  GtkWindow *window;
+  int default_width, default_height;
+  int width, height;
+  int font_size;
+  GdkScreen *screen;
+  int monitor_num;
+  GtkRequisition req;
+  GdkRectangle monitor;
+
+  widget = GTK_WIDGET (dialog);
+  window = GTK_WINDOW (dialog);
+
+  /* Size based on characters */
+
+  font_size = pango_font_description_get_size (widget->style->font_desc);
+  font_size = PANGO_PIXELS (font_size);
+
+  width = font_size * NUM_CHARS;
+  height = font_size * NUM_LINES;
+
+  /* Use at least the requisition size... */
+
+  gtk_widget_size_request (widget, &req);
+  width = MAX (width, req.width);
+  height = MAX (height, req.height);
+
+  /* ... but no larger than the monitor */
+
+  screen = gtk_widget_get_screen (widget);
+  monitor_num = gdk_screen_get_monitor_at_window (screen, widget->window);
+
+  gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
+
+  width = MIN (width, monitor.width * 3 / 4);
+  height = MIN (height, monitor.height * 3 / 4);
+
+  /* Set size */
+
+  gtk_window_get_default_size (window, &default_width, &default_height);
+
+  gtk_window_set_default_size (window,
+                              (default_width == -1) ? width : default_width,
+                              (default_height == -1) ? height : default_height);
+}
+
+static void
+gtk_file_chooser_dialog_realize (GtkWidget *widget)
+{
+  GTK_WIDGET_CLASS (parent_class)->realize (widget);
+  set_default_size (GTK_FILE_CHOOSER_DIALOG (widget));
+}
+
+static void
+gtk_file_chooser_dialog_style_set (GtkWidget *widget,
+                                  GtkStyle  *previous_style)
+{
+  if (GTK_WIDGET_CLASS (parent_class)->style_set)
+    GTK_WIDGET_CLASS (parent_class)->style_set (widget, previous_style);
+
+  if (GTK_WIDGET_REALIZED (widget))
+    set_default_size (GTK_FILE_CHOOSER_DIALOG (widget));
+}
+
+static void
+gtk_file_chooser_dialog_screen_changed (GtkWidget *widget,
+                                       GdkScreen *previous_screen)
+{
+  if (GTK_WIDGET_CLASS (parent_class)->screen_changed)
+    GTK_WIDGET_CLASS (parent_class)->screen_changed (widget, previous_screen);
+
+  if (GTK_WIDGET_REALIZED (widget))
+    set_default_size (GTK_FILE_CHOOSER_DIALOG (widget));
+}
+
 /**
  * gtk_file_chooser_dialog_new:
  * @title: Title of the dialog, or %NULL
@@ -208,10 +300,10 @@ gtk_file_chooser_dialog_get_property (GObject         *object,
  * @action: Open or save mode for the dialog
  * @first_button_text: stock ID or text to go in the first button, or %NULL
  * @Varargs: response ID for the first button, then additional (button, id) pairs, ending with %NULL
- * 
+ *
  * Creates a new #GtkFileChooserDialog.  This function is analogous to
  * gtk_dialog_new_with_buttons().
- * 
+ *
  * Return value: a new #GtkFileChooserDialog
  *
  * Since: 2.4
@@ -227,7 +319,7 @@ gtk_file_chooser_dialog_new (const gchar         *title,
   va_list varargs;
   const char *button_text = first_button_text;
   gint response_id;
-  
+
   result = g_object_new (GTK_TYPE_FILE_CHOOSER_DIALOG,
                         "title", title,
                         "action", action,